package org.dubnation.user.controller;

import org.dubnation.user.service.IWxUserService;
import org.dubnation.user.domain.WxUser;
import org.dubnation.user.query.WxUserQuery;
import org.dubnation.base.util.AjaxResult;
import org.dubnation.base.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wxuser")
public class WxUserController {
    @Autowired
    public IWxUserService wxuserService;


    /**
     * 保存和修改公用的
     * @param wxuser  传递的实体
     * @return Ajaxresult转换结果
     */
    @PutMapping
    public AjaxResult insertOrUpdate(@RequestBody WxUser wxuser){
        if( wxuser.getId()!=null)
            wxuserService.update(wxuser);
        else
            wxuserService.insert(wxuser);
        return AjaxResult.me();
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        wxuserService.delete(id);
        return AjaxResult.me();
    }
	
    //获取用户
    @GetMapping("/{id}")
    public AjaxResult queryById(@PathVariable("id")Long id) {
        WxUser wxuser = wxuserService.queryById(id);
        return AjaxResult.me().setData(wxuser);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping
    public AjaxResult queryAll(){
        List<WxUser> list = wxuserService.queryAll();
        return AjaxResult.me().setData(list);
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping
    public AjaxResult queryPage(@RequestBody WxUserQuery query){
        PageInfo<WxUser> pageInfo = wxuserService.queryPage(query);
        return AjaxResult.me().setData(pageInfo);
    }

    /**
    * 批量删除数据
    * @param ids
    * @return
*/
    @PatchMapping
    public AjaxResult batchDelete(@RequestBody List<Long> ids) {
        wxuserService.batchDelete(ids);
        return AjaxResult.me();
    }
}
